package com.heima.controller;

import com.heima.domain.dto.TextDTO;
import com.heima.domain.pojo.Result;
import com.heima.domain.pojo.Text;
import com.heima.domain.query.TextQueryParam;
import com.heima.domain.vo.PageVo;
import com.heima.service.TextService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/text")
public class TextController {
    @Autowired
    private TextService textService;

    @GetMapping("/pagelist")
    @Operation(description = "检验任务分页")
    public Result page(TextQueryParam textQueryParam){
        PageVo vo = textService.pageList(textQueryParam);
        return Result.success(vo);
    }

    @PostMapping("/add")
    @Operation(description = "新增")
    public Text add(@RequestBody TextDTO dto){
        Text text = textService.add(dto);
        return text;
    }

    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){
        textService.removeById(id);
        return Result.success();
    }
    @PutMapping("/update")
    public Result update(@RequestBody Text text){
        textService.updateById(text);
        return Result.success();
    }
}
